const user = require("../../api/user");

// pages/scan/scan.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.scanCode()
    },

    scanCode() {
        wx.scanCode({
            success(res) {
                console.log('scanCode', res, res.path.indexOf('&'))
                let path, scene, userId, id;
                if (res.path.indexOf('&')!= -1) {
                    path = res.path.split('?')[0];
                    scene = res.path.split('=')[1];
                    userId = scene.split('&')[0];
                    id = scene.split('&')[1];
                } else {
                    path = res.path.split('?')[0];
                    scene = res.path.split('=')[1];
                    userId = scene.split('%26')[0];
                    id = scene.split('%26')[1];
                }
                console.log('url=', '/' + path + '?id=' + id + '&userId=' + userId)
                wx.redirectTo({ url: '/' + path + '?id=' + id + '&userId=' + userId })
            }
        })
    },
})